
<template>
  <div class="yaBox">
    <div class="ya-block">
      <div class="ya-block-title">资产扫描默认配置</div>
      <div class="ya-block-content">
        <ya-form
          ref="formRef"
          :formColumns="formColumns"
          @handleEvent="handleEvent"
          :formData="formData"
        ></ya-form>
      </div>
    </div>
    <div class="ya-block">
      <div class="ya-block-title">扫描模式默认参数设置</div>
      <div class="ya-block-content ya-scan">
        <ya-form
          ref="formRefMode"
          :formColumns="formColumnsMode"
          @handleEvent="handleEventMode"
          :formData="formDataConfig"
        >
          <template #configInfo>
            <div class="level-height">
              <div>
                <!-- TCP端口扫描 -->
                <div class="level-top">
                  <div>TCP端口扫描</div>
                  <div
                    class="flex-bt"
                    style="width: 100%"
                    v-for="(item, index) in tcpPortList"
                    :key="index"
                  >
                    <el-radio
                      v-model="
                        formDataConfig.remoteScanDefaultConfig.detectScanConfig
                          .tcpPortScanRange
                      "
                      :label="item.value"
                    >
                      <span>{{ item.label }}</span>
                    </el-radio>
                    <div
                      v-if="item.value == 'standard'"
                      class="port-list"
                      @click="toPort"
                    >
                      编辑端口服务列表
                      <YaTooltip
                        placement="left"
                        trigger="hover"
                        content="标准端口扫描测策略扫描目标的已知各种应用、木马等使用的端口。"
                        :enterable="false"
                        :hide-after="0"
                      >
                        <svg
                          t="1660879085342"
                          class="icon QuestionFilled"
                          viewBox="0 0 1024 1024"
                          version="1.1"
                          xmlns="http://www.w3.org/2000/svg"
                          p-id="2208"
                          width="14"
                          height="14"
                        >
                          <path
                            d="M543.317333 650.837333c-6.656 8.106667-15.189333 13.909333-19.114666 12.202667-3.754667-1.450667-5.973333-5.888-4.864-10.24l53.845333-197.034667a43.52 43.52 0 0 0-5.717333-34.218666 34.986667 34.986667 0 0 0-27.733334-16.213334 140.373333 140.373333 0 0 0-91.392 72.106667 217.6 217.6 0 0 0 0 24.064l32.256-43.008c6.741333-8.106667 14.677333-13.909333 18.602667-12.544 4.010667 1.877333 6.144 6.826667 4.864 11.52L450.133333 653.653333c-6.058667 22.698667 5.546667 45.312 34.133334 50.432 41.813333 0 66.730667-31.146667 91.306666-71.424a215.296 215.296 0 0 0 0-24.746666l-32.256 43.008zM543.744 256c-17.664 0.170667-31.914667 17.066667-31.744 37.632 0.170667 20.650667 14.592 37.205333 32.256 37.034667 17.664-0.170667 31.914667-17.066667 31.744-37.632a39.68 39.68 0 0 0-9.386667-26.624A29.013333 29.013333 0 0 0 543.829333 256z"
                            p-id="2209"
                          ></path>
                          <path
                            d="M512 53.333333a458.666667 458.666667 0 1 0 0 917.333334A458.666667 458.666667 0 0 0 512 53.333333z m0 64a394.666667 394.666667 0 1 1 0 789.333334 394.666667 394.666667 0 0 1 0-789.333334z"
                            p-id="2210"
                          ></path>
                        </svg>
                      </YaTooltip>
                    </div>
                    <div v-if="item.value == 'fast'">
                      <YaTooltip
                        placement="left"
                        trigger="hover"
                        content="扫描1-1024"
                        :enterable="false"
                        :hide-after="0"
                      >
                        <svg
                          t="1660879085342"
                          class="icon QuestionFilled"
                          viewBox="0 0 1024 1024"
                          version="1.1"
                          xmlns="http://www.w3.org/2000/svg"
                          p-id="2208"
                          width="14"
                          height="14"
                        >
                          <path
                            d="M543.317333 650.837333c-6.656 8.106667-15.189333 13.909333-19.114666 12.202667-3.754667-1.450667-5.973333-5.888-4.864-10.24l53.845333-197.034667a43.52 43.52 0 0 0-5.717333-34.218666 34.986667 34.986667 0 0 0-27.733334-16.213334 140.373333 140.373333 0 0 0-91.392 72.106667 217.6 217.6 0 0 0 0 24.064l32.256-43.008c6.741333-8.106667 14.677333-13.909333 18.602667-12.544 4.010667 1.877333 6.144 6.826667 4.864 11.52L450.133333 653.653333c-6.058667 22.698667 5.546667 45.312 34.133334 50.432 41.813333 0 66.730667-31.146667 91.306666-71.424a215.296 215.296 0 0 0 0-24.746666l-32.256 43.008zM543.744 256c-17.664 0.170667-31.914667 17.066667-31.744 37.632 0.170667 20.650667 14.592 37.205333 32.256 37.034667 17.664-0.170667 31.914667-17.066667 31.744-37.632a39.68 39.68 0 0 0-9.386667-26.624A29.013333 29.013333 0 0 0 543.829333 256z"
                            p-id="2209"
                          ></path>
                          <path
                            d="M512 53.333333a458.666667 458.666667 0 1 0 0 917.333334A458.666667 458.666667 0 0 0 512 53.333333z m0 64a394.666667 394.666667 0 1 1 0 789.333334 394.666667 394.666667 0 0 1 0-789.333334z"
                            p-id="2210"
                          ></path>
                        </svg>
                      </YaTooltip>
                    </div>
                    <div
                      v-if="item.value == 'customize'"
                      class="m-l-8 port-range flex-one"
                    >
                      <el-input
                        v-model="
                          formDataConfig.remoteScanDefaultConfig
                            .detectScanConfig.tcpScanPort
                        "
                        placeholder="请输入1-65535"
                      ></el-input>
                      <YaTooltip
                        placement="left"
                        trigger="hover"
                        content="端口范围：1-65535；多个端口以英文“,”隔开；建议输入十个端口以内！"
                        :enterable="false"
                        :hide-after="0"
                      >
                        <svg
                          t="1660879085342"
                          class="icon QuestionFilled"
                          viewBox="0 0 1024 1024"
                          version="1.1"
                          xmlns="http://www.w3.org/2000/svg"
                          p-id="2208"
                          width="14"
                          height="14"
                        >
                          <path
                            d="M543.317333 650.837333c-6.656 8.106667-15.189333 13.909333-19.114666 12.202667-3.754667-1.450667-5.973333-5.888-4.864-10.24l53.845333-197.034667a43.52 43.52 0 0 0-5.717333-34.218666 34.986667 34.986667 0 0 0-27.733334-16.213334 140.373333 140.373333 0 0 0-91.392 72.106667 217.6 217.6 0 0 0 0 24.064l32.256-43.008c6.741333-8.106667 14.677333-13.909333 18.602667-12.544 4.010667 1.877333 6.144 6.826667 4.864 11.52L450.133333 653.653333c-6.058667 22.698667 5.546667 45.312 34.133334 50.432 41.813333 0 66.730667-31.146667 91.306666-71.424a215.296 215.296 0 0 0 0-24.746666l-32.256 43.008zM543.744 256c-17.664 0.170667-31.914667 17.066667-31.744 37.632 0.170667 20.650667 14.592 37.205333 32.256 37.034667 17.664-0.170667 31.914667-17.066667 31.744-37.632a39.68 39.68 0 0 0-9.386667-26.624A29.013333 29.013333 0 0 0 543.829333 256z"
                            p-id="2209"
                          ></path>
                          <path
                            d="M512 53.333333a458.666667 458.666667 0 1 0 0 917.333334A458.666667 458.666667 0 0 0 512 53.333333z m0 64a394.666667 394.666667 0 1 1 0 789.333334 394.666667 394.666667 0 0 1 0-789.333334z"
                            p-id="2210"
                          ></path>
                        </svg>
                      </YaTooltip>
                    </div>
                  </div>
                </div>
                <!-- TCP端口扫描方式 -->
                <div class="level-top radio-block">
                  <div>TCP端口扫描方式</div>
                  <el-radio-group
                    v-model="
                      formDataConfig.remoteScanDefaultConfig.detectScanConfig
                        .tcpPortScanType
                    "
                  >
                    <el-radio
                      v-for="(item, index) in tcpPortScanType"
                      :key="index"
                      :label="item.value"
                    >
                      <span>{{ item.label }}</span>
                      <span v-if="item.value == 0">
                        <YaTooltip
                          placement="left"
                          trigger="hover"
                          content="推荐选项，通过直接建立完整的TCP连接来判断端口开放情况，此方法快而准确！"
                          :enterable="false"
                          :hide-after="0"
                        >
                          <svg
                            t="1660879085342"
                            class="icon QuestionFilled"
                            viewBox="0 0 1024 1024"
                            version="1.1"
                            xmlns="http://www.w3.org/2000/svg"
                            p-id="2208"
                            width="14"
                            height="14"
                          >
                            <path
                              d="M543.317333 650.837333c-6.656 8.106667-15.189333 13.909333-19.114666 12.202667-3.754667-1.450667-5.973333-5.888-4.864-10.24l53.845333-197.034667a43.52 43.52 0 0 0-5.717333-34.218666 34.986667 34.986667 0 0 0-27.733334-16.213334 140.373333 140.373333 0 0 0-91.392 72.106667 217.6 217.6 0 0 0 0 24.064l32.256-43.008c6.741333-8.106667 14.677333-13.909333 18.602667-12.544 4.010667 1.877333 6.144 6.826667 4.864 11.52L450.133333 653.653333c-6.058667 22.698667 5.546667 45.312 34.133334 50.432 41.813333 0 66.730667-31.146667 91.306666-71.424a215.296 215.296 0 0 0 0-24.746666l-32.256 43.008zM543.744 256c-17.664 0.170667-31.914667 17.066667-31.744 37.632 0.170667 20.650667 14.592 37.205333 32.256 37.034667 17.664-0.170667 31.914667-17.066667 31.744-37.632a39.68 39.68 0 0 0-9.386667-26.624A29.013333 29.013333 0 0 0 543.829333 256z"
                              p-id="2209"
                            ></path>
                            <path
                              d="M512 53.333333a458.666667 458.666667 0 1 0 0 917.333334A458.666667 458.666667 0 0 0 512 53.333333z m0 64a394.666667 394.666667 0 1 1 0 789.333334 394.666667 394.666667 0 0 1 0-789.333334z"
                              p-id="2210"
                            ></path>
                          </svg>
                        </YaTooltip>
                      </span>
                      <span v-if="item.value == 1">
                        <YaTooltip
                          placement="left"
                          trigger="hover"
                          content=" 向目标端口发送SYN包，依据对方是否回复ACK报文来判断端口开放情况。"
                          :enterable="false"
                          :hide-after="0"
                        >
                          <svg
                            t="1660879085342"
                            class="icon QuestionFilled"
                            viewBox="0 0 1024 1024"
                            version="1.1"
                            xmlns="http://www.w3.org/2000/svg"
                            p-id="2208"
                            width="14"
                            height="14"
                          >
                            <path
                              d="M543.317333 650.837333c-6.656 8.106667-15.189333 13.909333-19.114666 12.202667-3.754667-1.450667-5.973333-5.888-4.864-10.24l53.845333-197.034667a43.52 43.52 0 0 0-5.717333-34.218666 34.986667 34.986667 0 0 0-27.733334-16.213334 140.373333 140.373333 0 0 0-91.392 72.106667 217.6 217.6 0 0 0 0 24.064l32.256-43.008c6.741333-8.106667 14.677333-13.909333 18.602667-12.544 4.010667 1.877333 6.144 6.826667 4.864 11.52L450.133333 653.653333c-6.058667 22.698667 5.546667 45.312 34.133334 50.432 41.813333 0 66.730667-31.146667 91.306666-71.424a215.296 215.296 0 0 0 0-24.746666l-32.256 43.008zM543.744 256c-17.664 0.170667-31.914667 17.066667-31.744 37.632 0.170667 20.650667 14.592 37.205333 32.256 37.034667 17.664-0.170667 31.914667-17.066667 31.744-37.632a39.68 39.68 0 0 0-9.386667-26.624A29.013333 29.013333 0 0 0 543.829333 256z"
                              p-id="2209"
                            ></path>
                            <path
                              d="M512 53.333333a458.666667 458.666667 0 1 0 0 917.333334A458.666667 458.666667 0 0 0 512 53.333333z m0 64a394.666667 394.666667 0 1 1 0 789.333334 394.666667 394.666667 0 0 1 0-789.333334z"
                              p-id="2210"
                            ></path>
                          </svg>
                        </YaTooltip>
                      </span>
                    </el-radio>
                  </el-radio-group>
                </div>
                <!-- UDP扫描端口 -->
                <div class="level-top">
                  <div class="scan-port">
                    UDP扫描端口
                    <span class="scan-port-chose"
                      ><el-switch
                        v-model="
                          formDataConfig.remoteScanDefaultConfig
                            .detectScanConfig.udpScanEnable
                        "
                    /></span>
                    <el-input
                      v-model="
                        formDataConfig.remoteScanDefaultConfig.detectScanConfig
                          .udpScanPort
                      "
                      placeholder="请输入1-65535"
                    ></el-input>
                    <YaTooltip
                      placement="left"
                      trigger="hover"
                      content="端口范围：1-65535；多个端口以英文“,”隔开；建议输入十个端口以内！"
                      :enterable="false"
                      :hide-after="0"
                    >
                      <svg
                        t="1660879085342"
                        class="icon QuestionFilled"
                        viewBox="0 0 1024 1024"
                        version="1.1"
                        xmlns="http://www.w3.org/2000/svg"
                        p-id="2208"
                        width="14"
                        height="14"
                      >
                        <path
                          d="M543.317333 650.837333c-6.656 8.106667-15.189333 13.909333-19.114666 12.202667-3.754667-1.450667-5.973333-5.888-4.864-10.24l53.845333-197.034667a43.52 43.52 0 0 0-5.717333-34.218666 34.986667 34.986667 0 0 0-27.733334-16.213334 140.373333 140.373333 0 0 0-91.392 72.106667 217.6 217.6 0 0 0 0 24.064l32.256-43.008c6.741333-8.106667 14.677333-13.909333 18.602667-12.544 4.010667 1.877333 6.144 6.826667 4.864 11.52L450.133333 653.653333c-6.058667 22.698667 5.546667 45.312 34.133334 50.432 41.813333 0 66.730667-31.146667 91.306666-71.424a215.296 215.296 0 0 0 0-24.746666l-32.256 43.008zM543.744 256c-17.664 0.170667-31.914667 17.066667-31.744 37.632 0.170667 20.650667 14.592 37.205333 32.256 37.034667 17.664-0.170667 31.914667-17.066667 31.744-37.632a39.68 39.68 0 0 0-9.386667-26.624A29.013333 29.013333 0 0 0 543.829333 256z"
                          p-id="2209"
                        ></path>
                        <path
                          d="M512 53.333333a458.666667 458.666667 0 1 0 0 917.333334A458.666667 458.666667 0 0 0 512 53.333333z m0 64a394.666667 394.666667 0 1 1 0 789.333334 394.666667 394.666667 0 0 1 0-789.333334z"
                          p-id="2210"
                        ></path>
                      </svg>
                    </YaTooltip>
                  </div>
                </div>
                <!-- 探活方式 -->
                <div class="level-top">
                  <div>探活方式</div>
                  <el-checkbox
                    disabled
                    v-model="
                      formDataConfig.remoteScanDefaultConfig.detectSurviveConfig
                        .icmpPing
                    "
                    label="true"
                    >ICMP PING</el-checkbox
                  >
                  <div class="flex-bt">
                    <el-checkbox
                      v-model="
                        formDataConfig.remoteScanDefaultConfig
                          .detectSurviveConfig.udpPing
                      "
                      label="true"
                    >
                      UDP PING端口
                    </el-checkbox>
                    <div class="m-l-12 ping-port flex-one">
                      <el-input
                        v-model="
                          formDataConfig.remoteScanDefaultConfig
                            .detectSurviveConfig.udpPort
                        "
                        placeholder="请输入1-65535"
                      ></el-input>
                      <YaTooltip
                        placement="left"
                        trigger="hover"
                        content="向目标主机发送UDP数据报文，根据目标主机的反应以判断其是否存活。"
                        :enterable="false"
                        :hide-after="0"
                      >
                        <svg
                          t="1660879085342"
                          class="icon QuestionFilled"
                          viewBox="0 0 1024 1024"
                          version="1.1"
                          xmlns="http://www.w3.org/2000/svg"
                          p-id="2208"
                          width="14"
                          height="14"
                        >
                          <path
                            d="M543.317333 650.837333c-6.656 8.106667-15.189333 13.909333-19.114666 12.202667-3.754667-1.450667-5.973333-5.888-4.864-10.24l53.845333-197.034667a43.52 43.52 0 0 0-5.717333-34.218666 34.986667 34.986667 0 0 0-27.733334-16.213334 140.373333 140.373333 0 0 0-91.392 72.106667 217.6 217.6 0 0 0 0 24.064l32.256-43.008c6.741333-8.106667 14.677333-13.909333 18.602667-12.544 4.010667 1.877333 6.144 6.826667 4.864 11.52L450.133333 653.653333c-6.058667 22.698667 5.546667 45.312 34.133334 50.432 41.813333 0 66.730667-31.146667 91.306666-71.424a215.296 215.296 0 0 0 0-24.746666l-32.256 43.008zM543.744 256c-17.664 0.170667-31.914667 17.066667-31.744 37.632 0.170667 20.650667 14.592 37.205333 32.256 37.034667 17.664-0.170667 31.914667-17.066667 31.744-37.632a39.68 39.68 0 0 0-9.386667-26.624A29.013333 29.013333 0 0 0 543.829333 256z"
                            p-id="2209"
                          ></path>
                          <path
                            d="M512 53.333333a458.666667 458.666667 0 1 0 0 917.333334A458.666667 458.666667 0 0 0 512 53.333333z m0 64a394.666667 394.666667 0 1 1 0 789.333334 394.666667 394.666667 0 0 1 0-789.333334z"
                            p-id="2210"
                          ></path>
                        </svg>
                      </YaTooltip>
                    </div>
                  </div>
                  <div class="flex-bt">
                    <el-checkbox
                      v-model="
                        formDataConfig.remoteScanDefaultConfig
                          .detectSurviveConfig.tcpPing
                      "
                      label="true"
                      :disabled="
                        formDataConfig.remoteScanDefaultConfig
                          .detectSurviveConfig.tcpPingAllPort
                          ? true
                          : false
                      "
                    >
                      TCP PING端口
                    </el-checkbox>
                    <div class="m-l-16 ping-port flex-one">
                      <el-input
                        v-model="
                          formDataConfig.remoteScanDefaultConfig
                            .detectSurviveConfig.tcpPort
                        "
                        placeholder="请输入1-65535"
                      ></el-input>
                      <YaTooltip
                        placement="left"
                        trigger="hover"
                        content="向目标主机TCP SYN/ACK/FIN等数据报文，根据目标主机的反应以判断其是否存活。"
                        :enterable="false"
                        :hide-after="0"
                      >
                        <svg
                          t="1660879085342"
                          class="icon QuestionFilled"
                          viewBox="0 0 1024 1024"
                          version="1.1"
                          xmlns="http://www.w3.org/2000/svg"
                          p-id="2208"
                          width="14"
                          height="14"
                        >
                          <path
                            d="M543.317333 650.837333c-6.656 8.106667-15.189333 13.909333-19.114666 12.202667-3.754667-1.450667-5.973333-5.888-4.864-10.24l53.845333-197.034667a43.52 43.52 0 0 0-5.717333-34.218666 34.986667 34.986667 0 0 0-27.733334-16.213334 140.373333 140.373333 0 0 0-91.392 72.106667 217.6 217.6 0 0 0 0 24.064l32.256-43.008c6.741333-8.106667 14.677333-13.909333 18.602667-12.544 4.010667 1.877333 6.144 6.826667 4.864 11.52L450.133333 653.653333c-6.058667 22.698667 5.546667 45.312 34.133334 50.432 41.813333 0 66.730667-31.146667 91.306666-71.424a215.296 215.296 0 0 0 0-24.746666l-32.256 43.008zM543.744 256c-17.664 0.170667-31.914667 17.066667-31.744 37.632 0.170667 20.650667 14.592 37.205333 32.256 37.034667 17.664-0.170667 31.914667-17.066667 31.744-37.632a39.68 39.68 0 0 0-9.386667-26.624A29.013333 29.013333 0 0 0 543.829333 256z"
                            p-id="2209"
                          ></path>
                          <path
                            d="M512 53.333333a458.666667 458.666667 0 1 0 0 917.333334A458.666667 458.666667 0 0 0 512 53.333333z m0 64a394.666667 394.666667 0 1 1 0 789.333334 394.666667 394.666667 0 0 1 0-789.333334z"
                            p-id="2210"
                          ></path>
                        </svg>
                      </YaTooltip>
                    </div>
                  </div>
                  <el-checkbox
                    v-model="
                      formDataConfig.remoteScanDefaultConfig.detectSurviveConfig
                        .tcpPingAllPort
                    "
                    :disabled="
                      formDataConfig.remoteScanDefaultConfig.detectSurviveConfig
                        .tcpPing
                        ? true
                        : false
                    "
                    label="true"
                    >TCP PING全端口</el-checkbox
                  >
                </div>
              </div>
            </div></template
          >
        </ya-form>
      </div>
    </div>
    <div class="ya-certain">
      <ya-button type="primary" @click="handlerModify">保存</ya-button>
    </div>
  </div>
</template>
<script lang="ts" setup>
import { ref, onMounted, reactive, watch } from "vue";
import {
  getGlobalConfig,
  modifyGlobalConfig,
} from "../../../api/system/globalConfig";
import { yaMessage } from "../../../utils/message";
import { getDictTypeList } from "../../../api/common";
import { useRouter } from "vue-router";
import { handleGetIndex } from "../../../utils/tools";
const router = useRouter();
//发包速率的校验
var checkRate = (rule, value, callback) => {
  if (value < 500) {
    callback(new Error("范围在500-200000"));
  } else if (value > 200000) {
    callback(new Error("范围在500-200000"));
  } else {
    callback();
  }
};
//重试次数的校验
var checkRetry = (rule, value, callback) => {
  if (value < 0) {
    callback(new Error("范围在0-8"));
  } else if (value > 8) {
    callback(new Error("范围在0-8"));
  } else {
    callback();
  }
};
//间隔时间的校验
var checkInterval = (rule, value, callback) => {
  if (value < 100) {
    callback(new Error("范围在100-1000"));
  } else if (value > 1000) {
    callback(new Error("范围在100-1000"));
  } else {
    callback();
  }
};
//超时时间的校验
var checkTimeout = (rule, value, callback) => {
  if (value < 1) {
    callback(new Error("范围在1-30"));
  } else if (value > 30) {
    callback(new Error("范围在1-30"));
  } else {
    callback();
  }
};

const detectModeList = ref([]);
const tcpPortList = ref([]);
const tcpPortScanType = ref([]);
//表单
const formColumns = ref([
  {
    key: "mode",
    type: "radio",
    label: "扫描模式",
    options: [
      {
        key: "快速模式",
        value: 0,
      },
      {
        key: "标准模式",
        value: 1,
      },
      {
        key: "精准模式",
        value: 2,
      },
    ],
    col: 24,
    onChange(data) {
      handlerChangeMode(data);
    },
  },
  {
    key: "rate",
    type: "input",
    label: "发包速率",
    isType: "number",
    col: 8,
    rules:[{ validator: checkRate, trigger: "change" }],
    tooltip:
      "存活探测每秒的发包数，快速模式默认值为10000，标准模式为8000，慢速模式为5000，自定义范围500-200000",
  },
  {
    key: "retry",
    type: "input",      
    label: "重试次数",
    isType: "number",
    col: 8,
    rules:[{ validator: checkRetry, trigger: "change" }],
    tooltip:
      "代表探测的过程中重新尝试的次数，快速模式默认值0，标准模式为2，慢速模式为3，自定义范围为0-8次",
  },
  {
    key: "interval",
    type: "input",
    label: "间隔时间",
    isType: "number",
    col: 8,
    rules:[{ validator: checkInterval, trigger: "change" }],
    tooltip:
      "针对单个IP的发包间隔时间，单位为毫秒（ms），快速模式默认值为100毫秒，标准模式为300毫秒，慢速模式默认值为500毫秒，自定义范围为100-1000毫秒",
  },
  {
    key: "timeout",
    type: "text",
    isType: "number",
    label: "超时时间",
    rules:[{ validator: checkTimeout, trigger: "change" }],
    col: 8,
    tooltip:
      "代表响应的最大等待时间，单位为秒（s）,快速模式默认值为3秒，标准模式为4秒，慢速默认值为5秒，自定义范围为1-30秒",
  },
]);
//表单的数据----资产扫描默认配置
const formData = ref({
  rate: null,
});
//表单的数据----扫描模式默认参数设置
const formDataConfig = ref({
  remoteScanDefaultConfig: {
    detectScanConfig: {
      tcpPortScanRange: null,
      tcpPortScanType: null,
      tcpScanPort: null,
      udpScanEnable: null,
      udpScanPort: null,
    },
    detectSurviveConfig: {
      icmpPing: null,
      tcpPing: null,
      tcpPingAllPort: null,
      tcpPort: null,
      udpPing: null,
      udpPort: null,
    },
    modeConfig: {
      mode: null,
    },
  },
});
const formColumnsMode = reactive([
  {
    key: "mode",
    label: "扫描模式",
    type: "select",
    options: detectModeList,
    col: 8,
    onChange(data) {
      choseSelect(data);
    },
  },
  {
    col: 16,
  },
  {
    disabled: false,
    key: "rate",
    label: "发包速率",
    type: "input",
    isType: "number",
    rules:[  { validator: checkRate, trigger: "change" }],
    col: 8,
    tooltip:
      "存活探测每秒的发包数，快速模式默认值为10000，标准模式为8000，慢速模式为5000，自定义范围500-200000。",
  },
  {
    col: 16,
  },
  {
    disabled: false,
    key: "retry",
    label: "重试次数",
    type: "input",
    isType: "number",
    col: 8,
    rules:[{ validator: checkRetry, trigger: "change" }],
    tooltip:
      "代表探测的过程中重新尝试的次数，快速模式默认值0，标准模式为2，慢速模式为3，自定义范围为0-8次。",
  },
  {
    col: 16,
  },
  {
    disabled: false,
    key: "interval",
    label: "间隔时间",
    type: "input",
    isType: "number",
    rules:[{ validator: checkInterval, trigger: "change" }],
    col: 8,
    tooltip:
      "针对单个IP的发包间隔时间，单位为毫秒（ms），快速模式默认值为100毫秒，标准模式为300毫秒，慢速模式默认值为500毫秒，自定义范围为100-1000毫秒。",
  },
  {
    col: 16,
  },
  {
    disabled: false,
    key: "timeout",
    label: "超时时间",
    type: "input",
    isType: "number",
    col: 8,
    rules:[{ validator: checkTimeout, trigger: "change" }],
    tooltip:
      "代表响应的最大等待时间，单位为秒（s）,快速模式默认值为3秒，标准模式为4秒，慢速默认值为5秒，自定义范围为1-30秒。",
  },
  {
    slotName: "configInfo",
  },
]);
//快速扫描时的表单数据
const formDataQuick = ref({});
//标准模式时的表单数据
const formDataStandard = ref({});
//慢速模式时的表单数据
const formDataLow = ref({});
//获取任务默认参数配置
const initData = (val?) => {
  getGlobalConfig().then((res) => {
    const { code, data = {} } = res || {};
    if (code == 200) {
      detectModeData.value = data.detectModeParamConfig;
      if (!val || val == 0) {
        for (let item in data.detectModeParamConfig.quick) {
          formData.value[item] = data.detectModeParamConfig.quick[item];
        }
      } else {
        if (val == 1) {
          for (let item in data.detectModeParamConfig.standard) {
            formData.value[item] = data.detectModeParamConfig.standard[item];
          }
        } else if (val == 2) {
          for (let item in data.detectModeParamConfig.slow) {
            formData.value[item] = data.detectModeParamConfig.slow[item];
          }
        }
      }
      formDataQuick.value = data.detectModeParamConfig.quick;
      formDataStandard.value = data.detectModeParamConfig.standard;
      formDataLow.value = data.detectModeParamConfig.slow;
      formDataConfig.value.remoteScanDefaultConfig =
        data.remoteScanDefaultConfig;
      for (let key in data.remoteScanDefaultConfig.modeConfig) {
        formDataConfig.value[key] =
          data.remoteScanDefaultConfig.modeConfig[key];
      }
      const i = handleGetIndex(formColumnsMode, "key", "rate");
      const j = handleGetIndex(formColumnsMode, "key", "timeout");
      for (let a = i; a < j + 1; a++) {
        formColumnsMode[a].disabled =
          data.remoteScanDefaultConfig.modeConfig.mode != 3;
      }
    }
  });
};
//模式的切换事件
const handlerChangeMode = (val) => {
  if (val == 0) {
    for (let item in formDataQuick.value) {
      formData.value[item] = formDataQuick.value[item];
    }
  } else if (val == 1) {
    for (let item in formDataStandard.value) {
      formData.value[item] = formDataStandard.value[item];
    }
  } else if (val == 2) {
    for (let item in formDataLow.value) {
      formData.value[item] = formDataLow.value[item];
    }
  }
};
/**
 * @description: 字典数据初始化
 */
const resetDictData = (e) => {
  let list = e.map((item) => {
    return {
      label: item.dictName,
      value: item.dictValue,
    };
  });
  return list;
};
//获取下拉框数据
const getDictList = () => {
  // 扫描模式
  getDictTypeList({ dictType: "detectMode" }).then((res) => {
    if (res.code == 200) {
      detectModeList.value = resetDictData(res.data).map((item) => {
        item.value = Number(item.value);
        return item;
      });
    }
  });
  // TCP端口扫描
  getDictTypeList({ dictType: "portScanRange" }).then((res) => {
    if (res.code == 200) {
      tcpPortList.value = resetDictData(res.data);
    }
  });
  // tcp 端口扫描方式
  getDictTypeList({ dictType: "tcpPortScanType" }).then((res) => {
    if (res.code == 200) {
      tcpPortScanType.value = resetDictData(res.data).map((item) => {
        item.value = Number(item.value);
        return item;
      });
    }
  });
};
const formRef = ref(null);
//点击确定按钮的校验事件
const handlerModify = () => {
  formRef.value && formRef.value.submitForm(formRef.value.ruleFormRef);
};
onMounted(() => {
  getDictList();
  initData();
});
//确定按钮的事件
const handleEvent = (data) => {
  if (data.eventName == "errorSubmit") {
    return;
  } else if (data.eventName == "successSubmit") {
    modifyEvent();
  }
};
const handleEventMode = () => {};
//修改数据的接口
const modifyEvent = () => {
  const data = JSON.parse(JSON.stringify(formData.value));
  switch (data.mode) {
    case 0:
      formDataQuick.value = data;
      break;
    case 1:
      formDataStandard.value = data;
      break;
    case 2:
      formDataLow.value = data;
      break;
  }
  let params = {
    detectModeParamConfig: {
      quick: formDataQuick.value,
      standard: formDataStandard.value,
      slow: formDataLow.value,
    },
    remoteScanDefaultConfig: formDataConfig.value.remoteScanDefaultConfig,
  };
  params.remoteScanDefaultConfig.modeConfig.mode = formDataConfig.value.mode;
  params.remoteScanDefaultConfig.modeConfig.interval =
    formDataConfig.value.interval;
  params.remoteScanDefaultConfig.modeConfig.rate = formDataConfig.value.rate;
  params.remoteScanDefaultConfig.modeConfig.retry = formDataConfig.value.retry;
  params.remoteScanDefaultConfig.modeConfig.timeout =
    formDataConfig.value.timeout;
  modifyGlobalConfig(params).then((res) => {
    const { code, message } = res;
    if (code == 200) {
      yaMessage(message, "success");
      initData(formData.value.mode);
    }
  });
  return;
};
/**
 * @desciption 监听扫描模式
 */
//不同扫描模式的数据
const detectModeData = ref({});
//扫描模式切换
const choseSelect = (val) => {
  const i = handleGetIndex(formColumnsMode, "key", "rate");
  const j = handleGetIndex(formColumnsMode, "key", "timeout");
  for (let a = i; a < j + 1; a++) {
    formColumnsMode[a].disabled = formDataConfig.value.mode != 3;
  }
  const data = ref({});
  if (val == 0) {
    data.value = detectModeData.value.quick;
  } else if (val == 1) {
    data.value = detectModeData.value.standard;
  } else if (val == 2) {
    data.value = detectModeData.value.slow;
  } else {
    data.value = {
      interval: 100,
      rate: 500,
      retry: 1,
      timeout: 1,
    };
  }
  formDataConfig.value.interval = data.value.interval || 0;
  formDataConfig.value.rate = data.value.rate || 0;
  formDataConfig.value.retry = data.value.retry || 0;
  formDataConfig.value.timeout = data.value.timeout || 0;
};
/**
 * @description: 端口策略列表
 */
const toPort = () => {
  router.push({
    path: "/system/systemConfig/portStrategy",
  });
};
</script>
<style lang="scss" scoped>
.yaBox {
  overflow-y: auto;
  .ya-block {
    width: 100%;
    padding: 0px 18px 0px 24px;
    background-color: #ffffff;
    box-sizing: border-box;
    .ya-block-title {
      height: 43px;
      line-height: 43px;
      font-size: 14px;
      font-family: PingFangSC-Medium, PingFang SC;
      font-weight: 500;
      color: rgba(0, 0, 0, 0.8);
      border-bottom: 1px solid rgba(0, 0, 0, 0.08);
    }
    .ya-block-content {
      margin-top: 12px;
    }
    .ya-scan {
      .level-height {
        font-size: var(--el-form-label-font-size);
        color: var(--el-text-color-primary);
        width: 100%;
        .level-top {
          margin-top: 10px;
        }
        .heighi-btn {
          font-weight: 500;
          color: #0079ea;
          text-decoration: underline;
          cursor: pointer;
        }
        .position-relative {
          position: relative;
        }
        .heighi-btn-icon {
          width: 0;
          height: 0;
          border-top: 5px solid #0079ea;
          border-left: 5px solid transparent;
          border-right: 5px solid transparent;
          position: absolute;
          top: 13px;
          left: 70px;
          cursor: pointer;
        }
        .heighi-btn-icon-up {
          border-top: none;
          border-bottom: 5px solid #0079ea;
          border-left: 5px solid transparent;
          border-right: 5px solid transparent;
        }
        .tip-icon {
          width: 14px;
          height: 14px;
          fill: rgba(0, 0, 0, 0.65);
          position: relative;
          top: 2px;
        }
      }
      .level-height1 {
        top: 0;
      }
      ::v-deep .ya-form .el-input {
        width: 100%;
      }
      .maring-top13 {
        margin-top: 13px;
      }
      .relative {
        position: relative;
      }
      .error-icon {
        color: #d90808;
      }
      .is-error {
        border: 1px solid #d90808;
        box-shadow: none;
        ::v-deep .el-input .el-input__wrapper:hover,
        ::v-deep .el-input .el-input__wrapper:focus {
          box-shadow: none;
        }
      }
      .QuestionFilled {
        cursor: pointer;
        fill: rgba(0, 0, 0, 0.8);
        position: relative;
        top: 2px;
        left: 5px;
      }
      ::v-deep .el-radio {
        // width: 100%;
        margin-bottom: 5px;
        margin-right: 5px;
      }
      ::v-deep .el-checkbox {
        // width: 98%;
        margin-bottom: 10px;
      }
      ::v-deep .el-radio__label,
      ::v-deep .el-checkbox__label {
        margin-left: 5px;
        color: rgba(0, 0, 0, 0.6);
        font-size: 14px;
        font-weight: 400;
      }
      .m-l-12 {
        margin-left: 12px;
      }
      .m-l-16 {
        margin-left: 16px;
      }
      .port-list {
        color: #0079ea;
        font-weight: 400;
        text-decoration: underline;
        position: relative;
        top: -3px;
        cursor: pointer;
      }
      ::v-deep .el-input {
        --el-border-radius-base: 2px;
      }
      .port-range {
        ::v-deep .el-input {
          width: calc(66.6% - 47px);
        }
      }
      .scan-port {
        .scan-port-chose {
          margin-left: 8px;
          margin-right: 15px;
        }
        ::v-deep .el-input {
          width: calc(66.6% - 160px);
        }
      }
      .ping-port {
        ::v-deep .el-input {
          width: calc(66.6% - 52px);
        }
      }
      ::v-deep .is-disabled,
      ::v-deep .is-checked {
        .el-checkbox__label,
        .el-radio__label {
          color: rgba(0, 0, 0, 0.6) !important;
        }
      }
      .percentage {
        position: relative;
        top: 13px;
      }
      .radio-block {
        ::v-deep .el-radio {
          width: 60%;
        }
      }
      .flex-bt {
        display: flex;
        flex-wrap: wrap;
        align-items: center;
      }
      .flex-one {
        flex: 1;
      }
      .m-l-8 {
        margin-left: 8px;
      }
      ::v-deep .tooltip-container {
        width: auto;
        max-width: 90%;
      }
    }
  }
  .ya-certain {
    background-color: #fff;
    padding: 0px 0px 24px 24px;
  }
}
</style>


